<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>正则表达式</title>
    <script>
        function f1(){
            let inText = document.getElementById("inText").value;
            let regExp = /^[a-z]$/i;
            let s1 = document.getElementById("s1");
            if(regExp.test(inText)){
                s1.innerHTML = "<span style='color:green;'>格式正确</span>";
            } else{
                s1.innerHTML = "<span style='color:red;'>格式错误</span>";
            }
        }
        function f2(){
            let inText = document.getElementById("inText").value;
            let regExp = new RegExp("^[a-z]$","i");
            let s1 = document.getElementById("s1");
            if(regExp.test(inText)){
                s1.innerHTML = "<span style='color:green;'>格式正确</span>";
            } else{
                s1.innerHTML = "<span style='color:red;'>格式错误</span>";
            }
        }
    </script>
</head>
<body>
<input type="text" id="inText"><span id="s1"></span><br>
<button onclick="f1()">定义方式一</button>
<button onclick="f2()">定义方式二</button>
</body>
</html>